#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>
#include<vector>
using namespace std;

    class Solution {
    public:
        string sortSentence(string s) {
            vector<string> v;
            v.resize(10);
            int pos = 0;
            int len = 0;
            int m = 0;
            for (auto& c : s)
            {
                if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
                    len++;
                else if (c >= '0' && c <= '9')
                {
                    m = (m < c - '0' ? c - '0' : m);
                    string tmp(s, pos, len);
                    v[c - '0'] = tmp;
                    pos += len + 2;
                    len = 0;
                }
                else
                    ;
            }
            string ret;

            for (int i = 1; i <= m; i++)
            {
                ret += v[i];
                if (i != m)
                    ret += ' ';
            }
            return ret;
        }
    };

int main()
{
    Solution s;
    string ret = s.sortSentence("QcGZ4 TFJStgu3 HvsRImLBfHd8 PaGqsPNo9 mZwxlrYzanuVOUZoyNjt1 fzhdtYIen6 mV7 LKuaOtefsixxo5 pwdEK2");
    cout << ret << endl;
    return 0;
}